<!DOCTYPE html>
{extend name="common/application" /}
{block name="title"}<title id="title">个人中心-课程收藏</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/help.css" />
<link rel="stylesheet" href="_CSS_/collect.css" />
{/block}



<!-- 主体内容 -->
{block name="content"}

			<div class="main">
				<div class="mainBody normalBox clearfix">
					<!--左菜单-->
					<ul class="menuList fl">
						<li>
							<a class="menuItem dropBg" href="personal.html"><span class="icons icon-account"></span>账户管理</a>
							<div class="childMenu">
								<a class="menuchildItem" href="personal.html">个人资料</a>
								<a class="menuchildItem" href="certification.html">实名认证</a>
								<a class="menuchildItem" href="account.html">账户安全</a>
							</div>
						</li>
						<li>
							<a class="menuItem dropBg" href="order.html"><span class="icons icon-order"></span>我的订单</a>
							<div class="childMenu">
								<a class="menuchildItem" href="order.html">我的订单</a>
							</div>
						</li>
						<li class="showChild">
							<a class="menuItem dropBg" href="collect_news.html"><span class="icons icon-collection"></span>我的收藏</a>
							<div class="childMenu">
								<a class="menuchildItem" href="collect_news.html">资讯收藏</a>
								<a class="menuchildItem activeMenu" href="collect_course.html">课程收藏</a>
								<a class="menuchildItem" href="collect_products.html">商品收藏</a>
								<a class="menuchildItem" href="collect_stores.html">店铺收藏</a>
							</div>
						</li>
						<li>
							<a class="menuItem dropBg" href="address.html"><span class="icons icon-address"></span>地址管理</a>
							<div class="childMenu">
								<a class="menuchildItem" href="address.html">地址管理</a>
							</div>
						</li>
						<li>
							<a class="menuItem dropBg" href="judge.html"><span class="icons icon-evaluate"></span>评价管理</a>
							<div class="childMenu">
								<a class="menuchildItem" href="judge.html">评价管理</a>
							</div>
						</li>
						<li>
							<a class="menuItem dropBg" href="complain.html"><span class="icons icon-price"></span>申述退款</a>
							<div class="childMenu">
								<a class="menuchildItem" href="complain.html">申述</a>
								<a class="menuchildItem" href="refund_money.html">退款</a>
							</div>
						</li>
						<li class="bb0">
							<a class="menuItem dropBg" href="message.html"><span class="icons icon-news"></span>消息中心</a>
							<div class="childMenu">
								<a class="menuchildItem" href="message.html">消息中心</a>
							</div>
						</li>
					</ul>
					<!--右内容-->
					<div class="menuContent fr">
						<div class="menuConHeader">
							<!--面包屑导航-->
							<div class="breadcrumb">
								<p>当前位置：
									<a href="collect_news.html">我的收藏</a> &gt;
									<a class="curPage" href="javascript:;">课程收藏</a>
								</p>
							</div>
						</div>
						<div class="menuConBody">
							<!--无数据-->
							<div class="noData hide">
								<img src="_IMG_/Nocollection.png"/>
								<p>还没有相关收藏，<a class="goLinks" href="/index.php/index/train/courses.html">前往课程中心</a>查看课程</p>
							</div>
							<div class="hasData">
								<div class="tableHeader">
									<input class="mainCheck" type="checkbox" />全选
									<span class="ml550">收藏时间</span>
									<span class="ml93">操作</span>
								</div>
								<div class="tableBody">

								</div>
								<div class="tableFoot">
									<input class="mainCheck" type="checkbox" />全选
									<a class="cancelAll" href="javascript:;">取消收藏</a>
								</div>
								<!--分页-->
								<div id="page">

								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
{/block}



{block name="js"}
		<!-- 脚本引入 -->

		<script src="_P_/laydate/laydate.js"></script>
<script src="_P_/layer/layer.js"></script>
<script src="_JS_/time.js"></script>
		<script type="text/javascript">
			//$('.title').html('课程收藏');
			$(document).ready(function(){
				var userinfo=$.cookie('userinfo');
				if(userinfo) {
					var user_login = $.base64.decode(userinfo).split(",");
					var uid = user_login[0];
					get_course(uid,1);
				}else{
					$('.hasData').html('');
					layer.msg('还未登录！', {icon: 5});
				}
				/*全选*/
				$(".mainCheck").change(function(){
					if($(this).prop('checked')){
						$(".mainCheck").prop('checked',true);
						$('.childCheck').prop('checked',true);
					}else{
						$(".mainCheck").prop('checked',false);
						$('.childCheck').prop('checked',false);
					}
				});
				/*勾选*/
				$('.childCheck').change(function(){
					var len = $('.items').length;
					var lens = $(this).parents('.tableBody').find('input[type="checkbox"]:checked').length;
					if($(this).prop('checked')){
						if(len == lens){
							$('.mainCheck').attr('checked',true);
						}else{
							$('.mainCheck').attr('checked',false);
						}
					}else{
						$('.mainCheck').attr('checked',false);
					}
				});
				//取消收藏
				$('.cancelAll').on('click',function(){
					var arrs = [];
					$('.tableBody input:checked').parents('.courses').each(function () {
						arrs.push($(this).attr('num'));
					});
					if (arrs.length == 0) {
						layer.msg('请选择需要取消的!', {icon: 1, time: 1000});
						return false;
					}
					var ids = arrs.join(",");
					cancle_collect(ids);
				});
				function cancle_collect(id){
					var page=$('.tableBody').attr('num');
					$.ajax({
						type: "get",
						url: "/index.php/api/account/cancel_video",
						data:{
							'id':id,
							'uid':uid,
							'form':'video',
							'sheet':'video'
						},
						dataType: 'jsonp',
						beforeSend: function () {
						var index = layer.load(1, {
							shade: [0.1, '#333333'] //0.1透明度的白色背景
						});
						},
						success: function (msg) {
							layer.closeAll();
							if(msg.code==200){
								layer.msg('取消收藏成功!', {icon: 1});
								get_course(uid,page);
							}
						}
					})
				}
				function get_course(uid,page){
					$.ajax({
						type: "get",
						url: "/index.php/api/account/course_list",
						data:{
							'uid':uid,
							'page':page
						},
						dataType: 'jsonp',
						success: function (msg) {
							if (msg.code == 200) {
								var html='';
								if(msg.data.count>0){
									for(var i=0;i<msg.data.data.length;i++){
										html+='<div class="items courses" num='+msg.data.data[i].c_id+'>';
										html+='<input class="fl childCheck" type="checkbox" />';
										html+='<div class="sectionItem fl"><a class="sectionImgbox fl" href="/index.php/index/train/courses_details.html?id='+msg.data.data[i].l_id+'">';
										html+='<img class="sectionImg" src="/Images/Cover/'+msg.data.data[i].pic+'"></a>';
										html+='<a class="sectionTitle text_overflow fl" href="/index.php/index/train/courses_details.html?id='+msg.data.data[i].l_id+'">'+msg.data.data[i].v_title+'</a>';
										html+='<p class="sectionSummary text_overflow fl">'+msg.data.data[i].v_views+'人学习</p>';
										html+='</div><span class="times">'+getMyDate(msg.data.data[i].c_time * 1000)+'</span><a class="cancelCollect" href="javascript:;">取消收藏</a></div>';
									}
									$('.tableBody').html(html);
									$('.tableBody').attr('num',page);
									$('#page').html(msg.data.render);
									$("#pagination").delegate("a", "click", function () {
										var num = $(this).attr("num");
										if (num) {
											get_course(uid,num);
										}
									});

								}else{
									$('.noData').removeClass('hide');
									$('.hasData').html('');
								}
							}
							if (msg.code == 1000) {
								$('.noData').removeClass('hide');
								$('.hasData').html('');
							}
							$('.cancelCollect').on('click',function(){
								var id=$(this).parents('.courses').attr('num');
								cancle_collect(id);
							})
						}
					});
				}
			});
		</script>
{/block}
